# 专利交底书AI助手 - 单文件发布脚本
# 作者: ATW-SCEC-Ingot group

Write-Host "=== 专利交底书AI助手 - 单文件发布 ===" -ForegroundColor Green
Write-Host "开始构建单文件版本..." -ForegroundColor Yellow

# 清理之前的构建
Write-Host "清理之前的构建..." -ForegroundColor Cyan
dotnet clean

# 还原包
Write-Host "还原NuGet包..." -ForegroundColor Cyan
dotnet restore

# 发布单文件版本
Write-Host "发布单文件版本..." -ForegroundColor Cyan
dotnet publish -c Release -r win-x64 --self-contained true -p:PublishSingleFile=true -p:PublishReadyToRun=true -p:IncludeNativeLibrariesForSelfExtract=true

# 检查发布结果
$publishPath = "bin\Release\net6.0-windows\win-x64\publish"
$exePath = "$publishPath\专利交底书AI助手.exe"

if (Test-Path $exePath) {
    $fileSize = [math]::Round((Get-Item $exePath).Length / 1MB, 2)
    Write-Host "`n=== 发布成功! ===" -ForegroundColor Green
    Write-Host "可执行文件路径: $exePath" -ForegroundColor White
    Write-Host "文件大小: $fileSize MB" -ForegroundColor White
    Write-Host "`n该文件包含完整的.NET运行时，可在任何Windows 10/11 x64系统上运行。" -ForegroundColor Cyan
    
    # 询问是否打开文件夹
    $openFolder = Read-Host "`n是否打开发布文件夹? (y/n)"
    if ($openFolder -eq 'y' -or $openFolder -eq 'Y') {
        Start-Process "explorer.exe" -ArgumentList $publishPath
    }
} else {
    Write-Host "`n=== 发布失败! ===" -ForegroundColor Red
    Write-Host "请检查错误信息并重试。" -ForegroundColor Red
}

Write-Host "`n按任意键退出..." -ForegroundColor Gray
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") 